home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_qt.idb / usr / freeware / include / Qt / qsize.h.z / qsize.h
Encoding:
C/C++ Source or Header  |  1998-10-28  |  5.3 KB  |  193 lines

  1. /****************************************************************************
  2. ** $Id: qsize.h,v 2.7 1998/07/03 00:09:41 hanord Exp $
  3. **
  4. ** Definition of QSize class
  5. **
  6. ** Created : 931028
  7. **
  8. ** Copyright (C) 1992-1998 Troll Tech AS.  All rights reserved.
  9. **
  10. ** This file is part of Qt Free Edition, version 1.40.
  11. **
  12. ** See the file LICENSE included in the distribution for the usage
  13. ** and distribution terms, or http://www.troll.no/free-license.html.
  14. **
  15. ** IMPORTANT NOTE: You may NOT copy this file or any part of it into
  16. ** your own programs or libraries.
  17. **
  18. ** Please see http://www.troll.no/pricing.html for information about 
  19. ** Qt Professional Edition, which is this same library but with a
  20. ** license which allows creation of commercial/proprietary software.
  21. **
  22. *****************************************************************************/
  23.  
  24. #ifndef QSIZE_H
  25. #define QSIZE_H
  26.  
  27. #ifndef QT_H
  28. #include "qpoint.h"
  29. #endif // QT_H
  30.  
  31. #if defined(QSIZE_C) || defined(DEBUG)
  32. #define QSIZE_DEBUG
  33. #endif
  34.  
  35.  
  36. class QSize
  37. {
  38. public:
  39.     QSize()    { wd = ht = -1; }
  40.     QSize( int w, int h );
  41.  
  42.     bool   isNull()    const;
  43.     bool   isEmpty()    const;
  44.     bool   isValid()    const;
  45.  
  46.     int       width()    const;
  47.     int       height()    const;
  48.     void   setWidth( int w );
  49.     void   setHeight( int h );
  50.     void   transpose();
  51.  
  52.     QSize expandedTo( const QSize & ) const;
  53.     QSize boundedTo( const QSize & ) const;
  54.  
  55.     QCOORD &rwidth();
  56.     QCOORD &rheight();
  57.  
  58.     QSize &operator+=( const QSize & );
  59.     QSize &operator-=( const QSize & );
  60.     QSize &operator*=( int c );
  61.     QSize &operator*=( float c );
  62.     QSize &operator/=( int c );
  63.     QSize &operator/=( float c );
  64.  
  65.     friend inline bool    operator==( const QSize &, const QSize & );
  66.     friend inline bool    operator!=( const QSize &, const QSize & );
  67.     friend inline QSize operator+( const QSize &, const QSize & );
  68.     friend inline QSize operator-( const QSize &, const QSize & );
  69.     friend inline QSize operator*( const QSize &, int );
  70.     friend inline QSize operator*( int, const QSize & );
  71.     friend inline QSize operator*( const QSize &, float );
  72.     friend inline QSize operator*( float, const QSize & );
  73. #if defined(QSIZE_DEBUG)
  74.     friend      QSize operator/( const QSize &, int );
  75.     friend      QSize operator/( const QSize &, float );
  76. #else
  77.     friend inline QSize operator/( const QSize &, int );
  78.     friend inline QSize operator/( const QSize &, float );
  79. #endif
  80.  
  81. private:
  82.     QCOORD wd;
  83.     QCOORD ht;
  84. };
  85.  
  86.  
  87. /*****************************************************************************
  88.   QSize stream functions
  89.  *****************************************************************************/
  90.  
  91. QDataStream &operator<<( QDataStream &, const QSize & );
  92. QDataStream &operator>>( QDataStream &, QSize & );
  93.  
  94.  
  95. /*****************************************************************************
  96.   QSize inline functions
  97.  *****************************************************************************/
  98.  
  99. inline QSize::QSize( int w, int h )
  100. { wd=(QCOORD)w; ht=(QCOORD)h; }
  101.  
  102. inline bool QSize::isNull() const
  103. { return wd==0 && ht==0; }
  104.  
  105. inline bool QSize::isEmpty() const
  106. { return wd<1 || ht<1; }
  107.  
  108. inline bool QSize::isValid() const
  109. { return wd>=0 && ht>=0; }
  110.  
  111. inline int QSize::width() const
  112. { return wd; }
  113.  
  114. inline int QSize::height() const
  115. { return ht; }
  116.  
  117. inline void QSize::setWidth( int w )
  118. { wd=(QCOORD)w; }
  119.  
  120. inline void QSize::setHeight( int h )
  121. { ht=(QCOORD)h; }
  122.  
  123. inline QCOORD &QSize::rwidth()
  124. { return wd; }
  125.  
  126. inline QCOORD &QSize::rheight()
  127. { return ht; }
  128.  
  129. inline QSize &QSize::operator+=( const QSize &s )
  130. { wd+=s.wd; ht+=s.ht; return *this; }
  131.  
  132. inline QSize &QSize::operator-=( const QSize &s )
  133. { wd-=s.wd; ht-=s.ht; return *this; }
  134.  
  135. inline QSize &QSize::operator*=( int c )
  136. { wd*=(QCOORD)c; ht*=(QCOORD)c; return *this; }
  137.  
  138. inline QSize &QSize::operator*=( float c )
  139. { wd=(QCOORD)(wd*c); ht=(QCOORD)(ht*c); return *this; }
  140.  
  141. inline bool operator==( const QSize &s1, const QSize &s2 )
  142. { return s1.wd == s2.wd && s1.ht == s2.ht; }
  143.  
  144. inline bool operator!=( const QSize &s1, const QSize &s2 )
  145. { return s1.wd != s2.wd || s1.ht != s2.ht; }
  146.  
  147. inline QSize operator+( const QSize & s1, const QSize & s2 )
  148. { return QSize(s1.wd+s2.wd, s1.ht+s2.ht); }
  149.  
  150. inline QSize operator-( const QSize &s1, const QSize &s2 )
  151. { return QSize(s1.wd-s2.wd, s1.ht-s2.ht); }
  152.  
  153. inline QSize operator*( const QSize &s, int c )
  154. { return QSize(s.wd*c, s.ht*c); }
  155.  
  156. inline QSize operator*( int c, const QSize &s )
  157. {  return QSize(s.wd*c, s.ht*c); }
  158.  
  159. inline QSize operator*( const QSize &s, float c )
  160. { return QSize((QCOORD)(s.wd*c), (QCOORD)(s.ht*c)); }
  161.  
  162. inline QSize operator*( float c, const QSize &s )
  163. { return QSize((QCOORD)(s.wd*c), (QCOORD)(s.ht*c)); }
  164.  
  165. #if !defined(QSIZE_DEBUG)
  166.  
  167. inline QSize &QSize::operator/=( int c )
  168. { wd/=(QCOORD)c; ht/=(QCOORD)c; return *this; }
  169.  
  170. inline QSize &QSize::operator/=( float c )
  171. { wd=(QCOORD)(wd/c); ht=(QCOORD)(ht/c); return *this; }
  172.  
  173. inline QSize operator/( const QSize &s, int c )
  174. { return QSize(s.wd/c, s.ht/c); }
  175.  
  176. inline QSize operator/( const QSize &s, float c )
  177. { return QSize((QCOORD)(s.wd/c), (QCOORD)(s.ht/c)); }
  178.  
  179. #endif // no-debug functions
  180.  
  181.  
  182. inline QSize QSize::expandedTo( const QSize & otherSize ) const
  183. {
  184.     return QSize( QMAX( wd, otherSize.wd ), QMAX( ht, otherSize.ht ) );
  185. }
  186.  
  187. inline QSize QSize::boundedTo( const QSize & otherSize ) const
  188. {
  189.     return QSize( QMIN( wd, otherSize.wd ), QMIN( ht, otherSize.ht ) );
  190. }
  191.  
  192. #endif // QSIZE_H
  193.